<?php declare(strict_types=1);
/**
 * This file is part of Swoft.
 *
 * @link     https://swoft.org
 * @document https://swoft.org/docs
 * @contact  group@swoft.org
 * @license  https://github.com/swoft-cloud/swoft/blob/master/LICENSE
 */

namespace App\Http\Controller\Test;

use App\Model\Logic\BreakerLogic;
use Exception;
use Swoft\Bean\Annotation\Mapping\Inject;
use Swoft\Http\Server\Annotation\Mapping\Controller;
use Swoft\Http\Server\Annotation\Mapping\RequestMapping;
use Swoft\Http\Server\Annotation\Mapping\RequestMethod;

/**
 * https://blog.csdn.net/github_26672553/article/details/82807188
 *
 * Class SwoftBreakerController
 *
 * @since 2.0
 *
 * @Controller(prefix="/Breaker")
 */
class SwoftBreakerController
{
    /**
     * @Inject()
     *
     * @var BreakerLogic
     */
    private $logic;

    /**
     * @RequestMapping(route="breaked",method={RequestMethod::GET})
     *
     * @return string
     * @throws Exception
     */
    public function breaked()
    {
        return $this->logic->func();
    }

    /**
     * @RequestMapping(route="un_break",method={RequestMethod::GET})
     *
     * @return array
     * @throws Exception
     */
    public function unbreak()
    {
        return [$this->logic->func2()];
    }

    /**
     * @RequestMapping(route="loop_braker",method={RequestMethod::GET})
     *
     * @return string
     * @throws Exception
     */
    public function loopBraker()
    {
        return $this->logic->loop();
    }

    /**
     * @RequestMapping(route="un_fallback",method={RequestMethod::GET})
     *
     * @return string
     * @throws Exception
     */
    public function unFallback()
    {
        return $this->logic->unFallback();
    }
}
